package com.zhkj.txg.module.login.ui

import com.blankj.utilcode.util.LogUtils
import com.zhkj.lib.base.ViewModelFragment
import com.zhkj.txg.R
import com.zhkj.txg.module.login.vm.LoginViewModel
import com.zhkj.txg.module.mine.ui.RechargeActivity
import com.zhkj.txg.utils.ThirdLoginUtils
import kotlinx.android.synthetic.main.fragment_login.*

class LoginFragment : ViewModelFragment<LoginViewModel>() {

    override val layoutResId = R.layout.fragment_login
    override fun setViewModel(): LoginViewModel = createViewModel(true)

    override fun initUI() {
        // 发送验证码按钮点击事件
//        btnSendCode.setOnClickListener {
//            val newAccount = etAccount.text.toString()
//            if (TextUtils.equals(newAccount, viewModel.mobile2GetCode)) {
//                viewModel.pageIndexLiveData.value = LoginActivity.Index.CAPTCHA
//            } else viewModel.sendCode(newAccount).takeIf {
//                !it.hasObservers()
//            }?.observe(viewLifecycleOwner, Observer {
//                handlerResponseStatus(it.status, it.statusTip)
//            })
//        }
        // 三方登录按钮点击事件
        tv_login_wx.setOnClickListener {
            if (checkboxCheckAgreement.isChecked) {
                ThirdLoginUtils.wxLogin(requireContext())
            } else {
                toast("请勾选同意用户服务协议和隐私政策")
            }
        }
//        // 判断账号长度是否符合规定
//        etAccount.addTextChangedListener(TextWatcherWrapper {
//            btnSendCode.isEnabled = !TextUtils.isEmpty(it) && it!!.length == 11
//        })
//        tvRule.setOnClickListener {
//            WelfareActivity.agreement(requireActivity(), tvRule.text.toString())
//        }
//        tvPolicy.setOnClickListener {
//            WelfareActivity.policy(requireActivity(), tvPolicy.text.toString())
//        }
        textCheckHideAgreement.setOnClickListener {
//            checkboxCheckAgreement.isChecked = !checkboxCheckAgreement.isChecked
            RechargeActivity.openCZ(
                requireActivity(),
                "隐私协议",
                "https://www.txemart.com/api/article/privacy"
            )
        }
        textCheckMemberAgreement.setOnClickListener {
//            checkboxCheckAgreement.isChecked = !checkboxCheckAgreement.isChecked

            RechargeActivity.openCZ(
                requireActivity(),
                "用户协议",
                "https://www.txemart.com/api/article/agreement"
            )
        }
        checkboxCheckAgreement.setOnCheckedChangeListener { _, isChecked ->
            if (isChecked) {
                tv_login_wx.setBackgroundResource(R.drawable.bg_gradient_100)
            } else {
                tv_login_wx.setBackgroundResource(R.drawable.bg_gradient)
            }
        }

    }
}